(function (factory) {
    if (typeof module === "object" && typeof module.exports === "object") {
        var v = factory(require, exports);
        if (v !== undefined) module.exports = v;
    }
    else if (typeof define === "function" && define.amd) {
        define(["require", "exports", "child_process"], factory);
    }
})(function (require, exports) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    const child_process_1 = require("child_process");
    const cmd = 'chcp 65001 && tasklist /FO CSV';
    const getSysTaskList = () => {
        return new Promise((resolve, reject) => {
            (0, child_process_1.exec)(cmd, (error, stdout, stderr) => {
                if (error) {
                    console.error(`exec error: ${error}`);
                    return;
                }
                if (stderr) {
                    console.error(`stderr: ${stderr}`);
                    return;
                }
                const lines = stdout.split('\r\n');
                lines.shift();
                lines.shift();
                lines.pop();
                const processes = lines.map((line) => {
                    const parts = line.split('","').map((item) => item.replaceAll('"', ''));
                    return {
                        ImageName: parts[0],
                        PID: Number(parts[1]),
                        SessionName: parts[2],
                        SessionNumber: parts[3],
                        MemUsage: parts[4]
                    };
                });
                resolve(processes);
            });
        });
    };
    exports.default = getSysTaskList;
});
